package com.wef.demo.service.impl;

import java.util.Collection;
import java.util.HashSet;
import java.util.Set;

import com.gfa4j.hibernate.BaseObject;
import com.gfa4j.service.impl.BaseServiceImpl;
import com.wef.demo.entity.Subject;
import com.wef.demo.entity.domain.SubjectDomain;
import com.wef.demo.service.SubjectService;

public class SubjectServiceImpl extends BaseServiceImpl implements SubjectService {

	public Subject loadSubjectById(String subjectId) {
		return (Subject) super.loadByPK(Subject.class, SubjectDomain.subjectId, subjectId);
	}

	public Subject addSubject(Subject subject) {
		subject = (Subject) super.saveObject(subject);
		return subject;
	}

	public Subject updateSubject(Subject subject) {
		return (Subject) super.updateObject(subject);
	}

	public void removeSubject(Subject subject) {
		this.deleteObject(subject);
	}

	public Subject saveOrUpdateSubject(Subject subject) {
		if (subject.getRowStatus() == BaseObject.ROWSTATUS_ADDED) {
			return this.addSubject(subject);
		}
		if (subject.getRowStatus() == BaseObject.ROWSTATUS_MODIFIED) {
			return this.updateSubject(subject);
		}
		if (subject.getRowStatus() == BaseObject.ROWSTATUS_DELETED) {
			this.removeSubject(subject);
		}
		return subject;
	}

	public Collection<Subject> saveOrUpdateSubjects(Set<Subject> entitys) {
		Set<Subject> retSubjects = new HashSet<Subject>();
		for (Subject entity : entitys) {
			retSubjects.add(saveOrUpdateSubject(entity));
		}
		return retSubjects;
	}
}